// JavaScript Document
	var pageLoaded = false;
  
  function fetchPage(pageTitle, parseOptions){

		var path = window.location.pathname;
		var boardLoc = path.substring(path.lastIndexOf('/') + 1);
		if(parseOptions != null){
			var page = boardLoc.split('#')[0] + '#' + pageTitle + ":" + parseOptions;
		} else {
			var page = boardLoc.split('#')[0] + '#' + pageTitle;
		}
		window.location = page;

		$('#loading').slideDown(200);
		$('#container_content_2').fadeOut(200, function(){
		  $.get("pages/"+pageTitle+".php?args="+parseOptions, function(data){
			 pageLoaded = true;
			 $("#container_content_2").html(data);
			 $('#loading').slideUp(200);
			 $("#container_content_2").fadeIn(200);
			 scrolltotop.init();
		  	//$('#container_content_2').slideDown(500);
		  });
		});
		
  }


  function getAnchor(Anchor){
	  if(Anchor.match('#')){
		  if(Anchor.match(':')){
			  args = Anchor.split(':')[1]
			  Anchor = Anchor.split(':')[0]
		  } else {
			  args = null;  
		  }
		  switch(Anchor){
			  case '#main':
				fetchPage('main', args)
			  break;
			  case '#reg':
				fetchPage('reg', args)
			  break;
			  case '#forum':
				fetchPage('forum', args)
			  break;
			  case '#board':
				fetchPage('board', args)
			  break;
			  case '#login':
				fetchPage('login', args)
			  break;
			  case '#profile':
				fetchPage('profile', args)
			  break;
			  case '#relpy':
				fetchPage('board', 1)
			  break;
			  case '#topic':
				fetchPage('topic', args)
			  break;
			  case '#logout':
				$.get('ajax/registration/logout.php', function(data){
															   //alert(data);
															   $("#loginout").html('<a id="no_highlight" href="#login">Login</a>')
															   $("#loginout").bind('click', function(){
																									 fetchPage('login')
																									 });
															   });
				fetchPage('forum', args);
			  break;
			  case '#val': 
			  	fetchPage('login', args);
			  break;
			  case '#memberlist':
			  	fetchPage('memberlist', args);
			  break;
			  default:
				fetchPage('main', args);
			  break; 
		  }
	  }
  }

  function reassert(tag){
	$(tag).click(function(){
	  var Anchor = $(this).attr("href");
	  getAnchor(Anchor);
	});
  }

$(document).ready(function(){      
	
	/*$("a").bind('click', function(){
	  alert("call");
	  var Anchor = $(this).attr("href");
	  getAnchor(Anchor);
	});*/

	$('#loading').hide();

		var initAnchor = window.location.toString();
		if(initAnchor.match('#')){
			initAnchor = initAnchor.split('#')[1]
			getAnchor("#"+initAnchor);
		} else {
			getAnchor("#main");
		}
	
});
